// 该文件用于创建整个应用的路由器
import VueRouter from "vue-router";
import { Message } from 'element-ui' //message消息提示
// 路由懒加载，需要的时候引入,创建并暴露一个路由器
const router = new VueRouter({
    routes:[
        {path:'/',redirect:'index'}, //默认路径
        // 路由,前台
        {
            path:'/index',
            component:()=>import("../pages/Index.vue"),
            meta:{showCopyright:true,showNav:true},
        },
        {
            name:'detail',
            path:'/detail',
            component:()=>import("../pages/Detail.vue"),
            meta:{showCopyright:true,showNav:true},
            props({query:{value}}){ //配置路由参数,组件中接收
                return {value:JSON.parse(value)}
            },
        },
        {
            path:'/settlement',
            name:'settlement',
            component:()=>import('../pages/Settlement.vue'),
            meta:{showCopyright:true,showNav:true},
            props({query:{value}}){
                return {value:JSON.parse(value)}
            }
        },
        {
            path:'/mall',
            component:()=>import("../pages/Mall.vue"),
            meta:{showCopyright:true,showNav:true}
        },
        {
            path:'/type',
            component:()=>import("../pages/Type.vue"),
            meta:{showCopyright:true,showNav:true},
            props({query:{type}}){ //配置路由params,组件中接收
                return {type:type}
            },
        },
        {
            path:'/car',
            component:()=>import("../pages/Car.vue"),
            meta:{showCopyright:true,showNav:true}
        },
        {
            path:'/user',
            component:()=>import("../pages/User.vue"),
            children:[
                {path:'/',redirect:'info'
                },
                {
                    path:'info',
                    meta:{showNav:true,showCopyright:true},
                    component:()=>import("../components/Person/Info.vue")
                },
                {
                    path:'order',
                    meta:{showNav:true,showCopyright:true},
                    component:()=>import("../components/Person/Order.vue")
                },
                {
                    path:'address',
                    meta:{showNav:true,showCopyright:true},
                    component:()=>import("../components/Person/Address.vue")
                },
                {
                    path:'footmark',
                    meta:{showNav:true,showCopyright:true},
                    component:()=>import("../components/Person/Footmark.vue")
                },
                {
                    path:'about',
                    meta:{showNav:true,showCopyright:true},
                    component:()=>import("../components/Person/About.vue")
                },
            ]
        },
        // 后台路由
        {
            path:'/admin',
            component:()=>import("../pages/admin/Admin.vue"),
        },
        { //backstage组件
            path:'/backstage',
            component:()=>import("../pages/admin/Backstage.vue"),
            // meta:{title:'品尚后台管理系统'},
            children:[
                {path:'/',redirect:'home'}, 
                {
                    path:'home',
                    meta:{title:'品尚后台管理系统-首页'},
                    component:()=>import("../pages/admin/Backstage/Home.vue"),
                },
                {
                    path:'goods',
                    meta:{title:'品尚后台管理系统-商品管理'},
                    component:()=>import("../pages/admin/Backstage/Goods.vue"),
                },
                {
                    path:'order',
                    component:()=>import("../pages/admin/Backstage/Order.vue"),
                },
                {
                    path:'user',
                    component:()=>import("../pages/admin/Backstage/User.vue"),
                },
                {
                    path:'more',
                    component:()=>import("../pages/admin/Backstage/More.vue"),
                },
            ]
        },
    ]
})
// 路由守卫
// router.beforeEach((to,from,next) => {
//     // 修改文档标题
//     // 进入结算页拦截
//     if (to.path === '/settlement') {
//         const local = localStorage.getItem('key')
//         if (local) {
//             next()
//         }else{
//             Message.warning({
//                 message:"用户未登录，跳转至登录页面中。。。",
//                 duration:2000,
//                 onClose:()=>{
//                     router.push("/user/info")
//                 }
//             })
//         }
//     }
//     next()
// })
export default router